import {server} from '../utils/http';
import { Injectable } from '@angular/core';
import * as util from 'app/utils';
import * as http from 'app/utils/http';
import feathers from 'feathers/client';
import socketio from 'feathers-socketio/client';
import io from 'socket.io-client/dist/socket.io';
import * as hooks from 'feathers-hooks';
import * as errors from 'feathers-errors';
import * as auth from 'feathers-authentication-client';

@Injectable()
export class FeathersService {

  public client: any
  public socket: any

  constructor() {
    const server = http.server

    this.socket = io(server, {transports: ['websocket']});
    this.client = feathers()
      .configure(socketio(this.socket))
      .configure(hooks())
      .configure(auth())

    this.test()
  }

  private test() {
    const w: any = window
    w.feathersClient = this.client
    w.socketClient = this.socket

    // feathersClient.service('database/buyer').get(1).then(console.log).catch(console.warn)

    // feathersClient.service('database/buyer').find({
    //   query: {
    //     id: {
    //       $in: [ 1, 2, 3 ]
    //     }
    //   }
    // }).then(console.log).catch(console.warn)

    // feathersClient.service('database/push').create({
    //     content: "XX",
    //     create_time: 1481624032,
    //     is_deleted: 0,
    //     is_system: true,
    //     status: false,
    //     summary: "",
    //     title: "WWI222",
    //     update_time: 0
    // }).then(console.log).catch(console.warn)

  //     feathersClient.service('database/push').update(20, {
  //     content: "XX2222",
  //     create_time: 1481624032,
  //     is_deleted: 0,
  //     is_system: true,
  //     status: false,
  //     summary: "",
  //     title: "22222",
  //     update_time: 0
  // }).then(console.log).catch(console.warn)

    // feathersClient.service('database/buyer').find().then(console.log).catch(console.warn)

    // feathersClient.service('database/push').remove(21).then(console.log).catch(console.warn)
 }

}
